<template>
  <div>
    <BasicModal v-bind="$attrs" @register="registerModal" title="SEO配置" @ok="handleSubmit">
      <BasicForm @register="registerForm" />
    </BasicModal>
  </div>
</template>

<script lang="ts">
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { SEOConfigFormSchema } from './personalManage.data';
  import { defineComponent } from 'vue';
  import { useMessage } from '/@/hooks/web/useMessage';

  export default defineComponent({
    components: {
      BasicModal,
      BasicForm,
    },
    emits: ['success', 'register'],
    setup(_, { emit }) {
      // 表单
      const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
        labelWidth: 100,
        schemas: SEOConfigFormSchema,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 23,
        },
      });

      // 模态框
      const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
        resetFields();
        setModalProps({ confirmLoading: false });
        setFieldsValue({
          ...data.record,
        });
      });

      const handleSubmit = async () => {
        try {
          // 表单校验
          const values = await validate();
          // 开启确定按钮的加载状态
          setModalProps({ confirmLoading: true });
          const { createMessage } = useMessage();
          console.log(values);
          createMessage.success('保存成功');
          emit('success');
          closeModal();
        } catch (err) {
          console.log(err);
        } finally {
          setModalProps({ confirmLoading: false });
        }
      };

      return {
        registerForm,
        registerModal,
        handleSubmit,
      };
    },
  });
</script>

<style scoped lang=""></style>
